<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Annotations</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="core-developers-guide.html">Core Developers Guide</a>&nbsp;&gt;&nbsp;<a href="annotations.html">Annotations</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Annotations</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14017">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14017">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14017">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14017">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14017">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14017">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><p>In many places, applications can use Java 5 annotations as an alternative to XML and Java properties configuration.  This page serves as a reference for all annotations across the framework.</p>

<h2 id="Annotations-ActionAnnotations">Action Annotations</h2>

<div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
<p>Since 2.1, these annotations are provided by the <a shape="rect" href="convention-plugin.html">Convention Plugin</a>. Codebehind and Zero Config plugins are deprecated from 2.1 on.</p></div></div>

<p>Action annotations are available when the framework scans the classpath for Action classes, rather than specifying individual mappings through XML configuration. See the <a shape="rect" href="convention-plugin.html">Convention Plugin</a> page for information on how to set up classpath scanning to allow the use of Action annotations.</p>

<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Annotation </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">Actions Annotation</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Group of @Action annotations, maps multiple URLs to the same action </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">Action Annotation</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Defines the URL of an action </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">InterceptorRefs Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Gropup of @InterceptorRef annotations </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">InterceptorRef Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Interceptor, or interceptor stack to be applied to at action </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">Results Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Group of @Result annotations </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">Result Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Defines a result for an action</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">Namespace Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Set the path of the action URL (used to overwrite the default)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">ResultPath Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Set where the results are located (used to overwrite the default)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">ParentPackage Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Set the parent package of the actions (used to overwrite the default)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">ExceptionMappings</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Group of @ExceptionMapping annotations</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="convention-plugin.html">ExceptionMapping</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Defines an exception mapping</p></td></tr></tbody></table></div>


<h2 id="Annotations-WorkflowAnnotations">Workflow Annotations</h2>

<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Annotation </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" href="inputconfig-annotation.html">InputConfig Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Defines what method to execute, or result to be returned if there are validation errors </p></td></tr></tbody></table></div>


<h2 id="Annotations-InterceptorAnnotations">Interceptor Annotations</h2>

<p>To use these annotations, you have to specify the <a shape="rect" href="annotationworkflowinterceptor.html">AnnotationWorkflowInterceptor</a> to your interceptor stack.</p>
<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Annotation </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="after-annotation.html">After Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Marks a action method that needs to be executed after the result. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="before-annotation.html">Before Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Marks a action method that needs to be executed before the main action method. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="beforeresult-annotation.html">BeforeResult Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Marks a action method that needs to be executed before the result. </p></td></tr></tbody></table></div>


<h2 id="Annotations-ValidationAnnotations">Validation Annotations</h2>

<p>To use annotation-based validation, annotate the class or interface with <a shape="rect" href="validation-annotation.html">Validation Annotation</a>.</p>

<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Annotation </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="conversionerrorfieldvalidator-annotation.html">ConversionErrorFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks if there are any conversion errors for a field. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="daterangefieldvalidator-annotation.html">DateRangeFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a date field has a value within a specified range. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="doublerangefieldvalidator-annotation.html">DoubleRangeFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a double field has a value within a specified range. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="emailvalidator-annotation.html">EmailValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a field is a valid e-mail address. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="expressionvalidator-annotation.html">ExpressionValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Validates an expression. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="fieldexpressionvalidator-annotation.html">FieldExpressionValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Uses an OGNL expression to perform its validator. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="intrangefieldvalidator-annotation.html">IntRangeFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a numeric field has a value within a specified range. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="regexfieldvalidator-annotation.html">RegexFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Validates a regular expression for a field. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="requiredfieldvalidator-annotation.html">RequiredFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a field is non-null. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="requiredstringvalidator-annotation.html">RequiredStringValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a String field is not empty. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="stringlengthfieldvalidator-annotation.html">StringLengthFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a String field is of the right length. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="urlvalidator-annotation.html">UrlValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Checks that a field is a valid URL. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="validation-annotation.html">Validation Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Marker annotation for validation at Type level. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="validations-annotation.html">Validations Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Used to group validation annotations. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="visitorfieldvalidator-annotation.html">VisitorFieldValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Invokes the validation for a property's object type. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="customvalidator-annotation.html">CustomValidator Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Use this annotation for your custom validator types. </p></td></tr></tbody></table></div>


<h3 id="Annotations-Resources">Resources </h3>
<ul><li><a shape="rect" class="external-link" href="http://arsenalist.com/2007/05/10/struts-2-validation-using-annotations/" rel="nofollow">Validation using Annotations</a> (arsenalist)</li></ul>


<h2 id="Annotations-TypeConversionAnnotations">Type Conversion Annotations</h2>

<p>By default, type conversion for Maps and Collections using generics is directly supported.</p>

<p>In short, instead of specifying the types found in collections and maps as documented in <a shape="rect" href="type-conversion.html">Type Conversion</a>, <strong>the  collection's generic type is used</strong>. By using annotations, an application should be able to avoid using any <code>ClassName-conversion.properties</code> files.</p>

<p>To use annotation-based type conversion, annotate the class or interface with the <a shape="rect" href="conversion-annotation.html">Conversion Annotation</a>.</p>

<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Annotation </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="conversion-annotation.html">Conversion Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Marker annotation for type conversions at Type level. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="createifnull-annotation.html">CreateIfNull Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> For Collection and Map types: Create the types within the Collection or Map, if null. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="element-annotation.html">Element Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> For Generic types: Specify the element type for Collection types and Map values. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="key-annotation.html">Key Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> For Generic types: Specify the key type for Map keys. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="keyproperty-annotation.html">KeyProperty Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> For Generic types: Specify the key property name value. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <a shape="rect" href="typeconversion-annotation.html">TypeConversion Annotation</a> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Used for class and application wide conversion rules. </p></td></tr></tbody></table></div>


<h2 id="Annotations-Next:">Next: <a shape="rect" href="configuration-elements.html">Configuration Elements</a></h2></div>
        </div>

                    <div class="tabletitle">
                Children
            <span class="smalltext" id="show" style="display: inline;">
              <a href="javascript:showChildren()">Show Children</a></span>
            <span class="smalltext" id="hide" style="display: none;">
              <a href="javascript:hideChildren()">Hide Children</a></span>
            </div>
            <div class="greybox" id="children" style="display: none;">
                                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                            </div>
        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
